from telnetlib import EC
from selenium import webdriver
import time

from selenium.webdriver.support import expected_conditions as EC

from selenium.webdriver.common.by import By
from selenium.webdriver.remote.webelement import WebElement
from selenium.webdriver.support.wait import WebDriverWait
options = webdriver.ChromeOptions()
options.add_argument("--headless")
options.add_argument("--disable-gpu")

driver = webdriver.Chrome(executable_path="/Users/rimi/Desktop/webdirver/chromedriver",
options=options)

driver.get("https://movie.douban.com/explore#!type=movie&tag=%E7%83%AD%E9%97%A8&sort=recommend&page_limit=20&page_start=0")
# time.sleep(1)

try:
    # 等待期待条件发生
    WebDriverWait(driver,1).until(EC.presence_of_element_located((By.TAG_NAME)))

except Exception as e:
    print(e)

# 一直循环电影
# time.sleep(10)
# #while ture:
# next_page = driver.find_element_by_class_name('more')
# next_page.click()
# time.sleep(5)
#

tag = driver.find_element_by_class_name("list")
assert isinstance(tag, WebElement)
for t in tag.find_elements_by_class_name("item"):
    title = t.find_element_by_tag_name("p")
    score = t.find_element_by_tag_name('strong')
    # username = user_info[0].text
    # age = user_info[1].text
    # gender = user_info[2].text

    print(title.text,score.text)

# time.sleep(5)
# search_tag = driver.find_element_by_name('search_text')
# search_tag.send_keys('周星驰')
# search_tag.submit()
# time.sleep(30)
# print(type(tag))

# print(driver.title)
# time.sleep(10)
driver.quit()